import 'dart:convert';

import 'package:qunaimedical/models/doctor.dart';

class ConsultationRecord {
  String id,
      doctorId,
      fullname,
      avatar,
      showImg,
      office,
      sectionTypeNameDoctor, // 医生科室类型
      sectionTypeName, // 单子科室类型
      status,
      freeTime,
      morningAfternoon,
      title,
      skilled,
      professionalName,
      consultationTypeName,
      appointmentImag,
      whetherAppointed,
      video,
      meetingUrl,
      content;

  List<Doctor> doctorInfoList;

  ConsultationRecord({
    this.id,
    this.doctorId,
    this.fullname,
    this.avatar,
    this.showImg,
    this.office,
    this.sectionTypeName,
    this.sectionTypeNameDoctor,
    this.status,
    this.freeTime,
    this.morningAfternoon,
    this.title,
    this.content,
    this.skilled,
    this.professionalName,
    this.appointmentImag,
    this.whetherAppointed,
    this.video,
    this.meetingUrl,
    this.consultationTypeName,
    this.doctorInfoList,
  });

  factory ConsultationRecord.fromJson(Map<String, dynamic> data) {
    return ConsultationRecord(
      id: data['id'],
      doctorId: data['doctorId'],
      fullname: data['fullname'],
      avatar: data['avatar'],
      showImg: data['showImg'],
      office: data['office'],
      sectionTypeName: data['sectionTypeName'],
      sectionTypeNameDoctor: data['sectionTypeNameDoctor'],
      status: data['status'],
      freeTime: data['freeTime'],
      morningAfternoon: data['morningAfternoon'],
      title: data['title'],
      content: data['content'],
      skilled: data['skilled'],
      professionalName: data['professionalName'],
      consultationTypeName: data['consultationTypeName'],
      appointmentImag: data['appointmentImag'],
      whetherAppointed: data['whetherAppointed']?.toString(),
      video: data['video'],
      meetingUrl: data['meetingUrl'],
      doctorInfoList:
          data['doctorInfoList'] == null || data['doctorInfoList'] == ''
              ? []
              : ((data['doctorInfoList'] as List)
                  .map((e) => Doctor.fromJson(e))
                  .toList()),
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'doctorId': doctorId,
      'fullname': fullname,
      'avatar': avatar,
      'office': office,
      'sectionTypeName': sectionTypeName,
      'sectionTypeNameDoctor': sectionTypeNameDoctor,
      'status': status,
      'freeTime': freeTime,
      'morningAfternoon': morningAfternoon,
      'title': title,
      'content': content,
      'skilled': skilled,
      'professionalName': professionalName,
      'consultationTypeName': consultationTypeName,
      'appointmentImag': appointmentImag,
      'whetherAppointed': whetherAppointed,
      'video': video,
      'meetingUrl': meetingUrl,
    };
  }

  @override
  String toString() {
    return json.encode(toMap());
  }
}
